package com.aco.party.security.matcher;

import com.aco.party.security.token.OpenIdAuthenticationToken;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;

/**
 * Created by WangShijun on 2016/5/21.
 */
public class PasswordHashedMatcher extends HashedCredentialsMatcher{
    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        //如果是openId方式进入，则不进行密码校验
        if(token.getClass().isAssignableFrom(OpenIdAuthenticationToken.class)){
            return true;
        }else {
            Object tokenHashedCredentials = hashProvidedCredentials(token, info);
            Object accountCredentials = getCredentials(info);
            return equals(tokenHashedCredentials, accountCredentials);
        }
    }
}
